package logic

import (
	"context"
	"errors"
	"month2/B/rpc_B/model/mysql"

	"month2/B/rpc_B/internal/svc"
	"month2/B/rpc_B/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateUserStatusLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateUserStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserStatusLogic {
	return &UpdateUserStatusLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateUserStatusLogic) UpdateUserStatus(in *user.UpdateUserStatusRequest) (*user.UpdateUserStatusResponse, error) {
	u := mysql.User2{}
	err := u.UpdateUserStatus(int(in.UserId), int(in.Status))
	if err != nil {
		logx.Error("用户状态修改失败")
		return nil, errors.New("用户状态修改失败")
	}
	return &user.UpdateUserStatusResponse{
		Success: true,
	}, nil
}
